home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / outtolod.lzh / OUTTOLOD.C next >
C/C++ Source or Header  |  1992-05-08  |  6KB  |  281 lines

  1. /***************************************/
  2. /*                                     */
  3. /* OUT To LOD DSP 56001 File Converter */
  4. /*                                     */
  5. /*      Gabriel Sebestyen - 1993       */
  6. /*                                     */
  7. /***************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <tos.h>
  12.  
  13. #define MAXLEN 256
  14. #define START "_START"
  15. #define DATA  "_DATA"
  16. #define END   "_END"
  17. #define SPACE " "
  18. #define ENTER "\r\n"
  19. #define PMEM  "P"
  20. #define XMEM  "X"
  21. #define YMEM  "Y"
  22. #define NAME  "TEST"
  23. #define DSP   "DSP56001 4.1.1"
  24. #define FOURNULL "0000"
  25. #define MAXDATAS 8
  26.  
  27. char *String[ MAXLEN ];
  28. int  Length;
  29.  
  30. char ReadByte ( int );
  31. void WriteByte ( int , char );
  32. int ReadString ( int , char * );
  33. void WriteString ( int , char * );
  34. int CmpStr ( char * ,char * );
  35. int StrToNum ( char * );
  36.  
  37. void main ( argc , argv )
  38. int argc;
  39. char *argv[];
  40.     {
  41.         char *Fname ,*Fmem;
  42.         char *From;
  43.         int  TstLen = 0;
  44.         int Rhandle ,Whandle;
  45.         int ActAddr = 0;
  46.         int NewAddr;
  47.         char *ActMem = "x";
  48.         int LineCounter = 0;
  49.         char *String = "                       ";
  50.         int Status = 0;
  51.         if ( argc < 2 || *argv[1] == '?' )
  52.             {
  53.                 printf ( ".OUT to .LOD Converter v01\n" );
  54.                 printf ( "Written By Gabriel Sebestyen\n" );
  55.                 printf ( "Input: .OUT DSP-ASCII file made by A56.TTP\n" );
  56.                 printf ( "Output: .LOD file ... \n" );
  57.                 getch ();
  58.                 exit ( 1 );
  59.             }
  60.         Fmem = Malloc ( 100 );
  61.  
  62.         Fname = Fmem;
  63.         From = argv[1];
  64.         while ( *From != 0x0000 )
  65.             {
  66.                 *Fname++ = *From++ ;
  67.                 TstLen ++;
  68.             }
  69.         while ( *Fname != '.' || TstLen-- == 0x0000 )
  70.                 Fname--;
  71.         
  72.         if ( *Fname != '.' )
  73.             {
  74.                 printf ( "Wrong filename!\n" );
  75.                 exit ( 1 );
  76.             }
  77.         
  78.         Fname++;
  79.         *Fname++ = 'L';
  80.         *Fname++ = 'O';
  81.         *Fname++ = 'D';
  82.         *Fname++ = 0x00;
  83.         Fname = Fmem;
  84.     
  85.         printf ( "Working ...\n" );
  86.         
  87.         Rhandle = Fopen ( argv[1] , 0 );
  88.         if ( Rhandle < 0 )
  89.             {
  90.                 printf ( "Can't open file %s !\n" ,argv[1] );
  91.                 exit ( 1 );
  92.             }
  93.         Whandle = Fcreate ( Fname , 0 );
  94.         if ( Whandle < 0 )
  95.             {
  96.                 printf ( "Can't open file %s !\n" ,Fname );
  97.                 exit ( 1 );
  98.             }
  99.         
  100.         WriteString ( Whandle , START );
  101.         WriteString ( Whandle , SPACE );
  102.         WriteString ( Whandle , NAME );
  103.         WriteString ( Whandle , SPACE );
  104.         WriteString ( Whandle , FOURNULL );
  105.         WriteString ( Whandle , SPACE );
  106.         WriteString ( Whandle , FOURNULL );
  107.         WriteString ( Whandle , SPACE );
  108.         WriteString ( Whandle , FOURNULL );
  109.         WriteString ( Whandle , SPACE );
  110.         WriteString ( Whandle , DSP );
  111.         WriteString ( Whandle , ENTER );
  112.  
  113.         while ( Status == 0 )
  114.             {
  115.                 if ( ReadString ( Rhandle , String ) == -1 )
  116.                     break;
  117.                 if ( *String != *ActMem )
  118.                     {
  119.                         *ActMem = *String;
  120.                         *( ActMem +1 ) = 0;
  121.                         
  122.                         WriteString ( Whandle , ENTER );
  123.                         WriteString ( Whandle , DATA );
  124.                         WriteString ( Whandle , SPACE );
  125.                         WriteString ( Whandle , ActMem );
  126.                         WriteString ( Whandle , SPACE );
  127.                         ReadString ( Rhandle , String );
  128.                         WriteString ( Whandle , String );
  129.                         WriteString ( Whandle , ENTER );
  130.                         ActAddr = StrToNum ( String );
  131.                         LineCounter = 0;
  132.                     }
  133.                 else
  134.                     {
  135.                         ReadString ( Rhandle , String );
  136.                         NewAddr = StrToNum ( String );
  137.                         if ( ActAddr  != NewAddr )
  138.                             {
  139.                                 ActAddr = NewAddr;
  140.                                 WriteString ( Whandle , ENTER );
  141.                                 WriteString ( Whandle , DATA );
  142.                                 WriteString ( Whandle , SPACE );
  143.                                 WriteString ( Whandle , ActMem );
  144.                                 WriteString ( Whandle , SPACE );
  145.                                 WriteString ( Whandle , String );
  146.                                 WriteString ( Whandle , ENTER );
  147.                                 LineCounter = 0;
  148.                             }
  149.                     }
  150.  
  151.                     ReadString ( Rhandle , String );
  152.                     WriteString ( Whandle , String );
  153.                     if ( LineCounter == 7 )
  154.                         {
  155.                             WriteString ( Whandle , ENTER );
  156.                             LineCounter = 0;
  157.                         }
  158.                     else
  159.                         {
  160.                             WriteString ( Whandle , SPACE );
  161.                             LineCounter++;
  162.                         }
  163.                     ActAddr++;
  164.             }
  165.         
  166.         WriteString ( Whandle , ENTER );        
  167.         WriteString ( Whandle , END );        
  168.         WriteString ( Whandle , SPACE );        
  169.         WriteString ( Whandle , FOURNULL );        
  170.         WriteString ( Whandle , ENTER );        
  171.  
  172.         Fclose ( Whandle );
  173.         Fclose ( Rhandle );
  174.         Mfree ( Fmem );
  175.  
  176.         
  177.     }
  178.  
  179. char ReadByte ( Rhandle )
  180. int Rhandle;
  181.     {
  182.         char Byte;
  183.         int Erreur;
  184.         
  185.         Erreur = Fread ( Rhandle , 1 , &Byte );
  186.         if ( Erreur < 1 )
  187.             Byte = 0xFF;
  188.         return ( Byte );
  189.     }
  190.  
  191. void WriteByte ( Whandle , Byte )
  192. int Whandle;
  193. char Byte;
  194.     {
  195.         int Erreur;
  196.         
  197.         Erreur = Fwrite ( Whandle , 1 , &Byte );
  198.         if ( Erreur < 0 )
  199.             {
  200.                 printf ( "Write Error!\n" );
  201.                 exit ( 1 );
  202.             }
  203.     }
  204.  
  205. int ReadString ( Rhandle , Spointer )
  206. int Rhandle;
  207. char *Spointer;
  208.     {
  209.         int i;
  210.         char Byte = ' ';
  211.         
  212.         while ( Byte <= ' ' && Byte >= 1 )
  213.             Byte = ReadByte ( Rhandle );
  214.  
  215.         if ( Byte == 0xFF )
  216.             return ( -1 );
  217.  
  218.         *Spointer++ = Byte;
  219.         
  220.         for ( i = 0 ; i < MAXLEN ; i++)
  221.             {
  222.                 Byte = ReadByte ( Rhandle );
  223.                 if ( Byte == 0xFF )
  224.                     return ( -1 );
  225.                 
  226.                 if ( Byte > ' ' )
  227.                     *Spointer++ = Byte;
  228.                 else
  229.                     break;
  230.             }
  231.         *Spointer++ = 0x00;
  232.         return ( 0 );
  233.     }
  234.  
  235. void WriteString ( Whandle , Spointer )
  236. int Whandle;
  237. char *Spointer;
  238.     {
  239.         while ( *Spointer != 0x00 )
  240.             WriteByte ( Whandle , *Spointer++ );
  241.     }
  242.  
  243. int CmpStr ( String1 , String2 )
  244. char *String1 , *String2;
  245.     {
  246.         int Len = 0x0000;
  247.         
  248.         while ( *String1++ == *String2 ++ )
  249.             Len++;
  250.         return ( Len );
  251.     }
  252.  
  253. int StrToNum ( String1 )
  254. char *String1;
  255.     {
  256.         int number = 0;
  257.         unsigned int hexa = 1;
  258.         char byte;
  259.         int counter = 0;
  260.  
  261.         while ( *String1++ != 0x00 )
  262.             counter++;
  263.         
  264.         if ( counter == 0 )
  265.             return ( 0 );
  266.             
  267.         String1--;
  268.         String1--;
  269.         
  270.         while ( counter-- > 0 )
  271.             {
  272.                 byte = *String1--;
  273.                 if ( byte >= '0' && byte <= '9' )
  274.                     number += ( byte - '0' ) * hexa;
  275.                 else if ( byte >= 'A' && byte <= 'F' )
  276.                     number += ( ( byte - 'A' ) + 10 ) * hexa;
  277.                 hexa *= 16;
  278.             }
  279.         return ( number );
  280.     }
  281.